﻿using System;
using System.Threading;
using Microsoft.Commerce.Common;
using Microsoft.Commerce.Common.MessageBuilders;
using Microsoft.Commerce.Contracts;
using Microsoft.Commerce.Contracts.Messages;
using Microsoft.Samples.Commerce.Catalog.CommerceEntities;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Samples.Commerce.Order;
using Microsoft.Samples.Commerce.Order.CommerceEntities;


namespace CommerceConsole {
    class Program {

         
        static void Main(string[] args) {

          string paymentMethodId = "DFD85562-9061-4227-AA64-C7F3C8BD4489";
            string shippingMethodId="D38B1B4D-30DF-46E1-8EE1-F4B37263B17B";
            List<string> mystr = new List<string>();

          Basket mybskt=  BasketManager.AddLineItem( new Microsoft.Samples.Commerce.Order.CommerceEntities.LineItem("Adventure Works Catalog","AW075-03","64",1));

            foreach (var myItem in mybskt.LineItems)
            {
                mystr.Add(myItem.Target.Id);
            }

            
            var  myShippingAddress = new Address();

            myShippingAddress.AddressName = "any";
            myShippingAddress.AddressType = 2;
            myShippingAddress.City = "city";
            myShippingAddress.FirstName = "first name";
            myShippingAddress.Id = Guid.NewGuid().ToString();


            var myBillingAddress = new Address();

            myBillingAddress.AddressName = "any name";
            myBillingAddress.AddressType = 2;
            myBillingAddress.City = "city 2";
            myBillingAddress.FirstName = "first name for billing";
            myBillingAddress.LastName = "last name for billing";

            myBillingAddress.Id = Guid.NewGuid().ToString();
            
             var myCreditCard = new CreditCard();

             myCreditCard.AuthorizationCode = "AuthCode";
             myCreditCard.CustomerName = "custName";
             myCreditCard.CreditCardNumber = "4111111111111111";
             myCreditCard.DisplayName = "test displayname";
             myCreditCard.ExpirationMonth = 1;
             myCreditCard.ExpirationYear = 2015;

             myCreditCard.BillingAddressId = myBillingAddress.Id;

             myCreditCard.PaymentMethod = new CommerceRelationship();
             myCreditCard.PaymentMethod.Id = paymentMethodId;

             BasketManager.PrepareForCheckout(myShippingAddress, myBillingAddress, myCreditCard, shippingMethodId, mystr.ToArray<string>(), paymentMethodId);

            BasketManager.Checkout();

            Console.WriteLine("order Placed...");
            Console.ReadKey();
        }

        
    }
}
